package com.leadnews.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leadnews.pojo.Message;
import com.leadnews.service.MessageService;
import com.leadnews.mapper.MessageMapper;
import com.leadnews.vo.MessageVo;
import com.leadnews.vo.ResponseResult;
import com.leadnews.vo.UserVo;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.leadnews.utils.AppJwtUtil.getClaimsBody;

/**
* @author 自己
* @description 针对表【message】的数据库操作Service实现
* @createDate 2023-01-25 10:53:57
*/
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message>
    implements MessageService{
@Autowired
MessageMapper messageMapper;
    @Override
    public ResponseResult findMessage(Map<String,String> userVo) {
        String token = userVo.get("token");
        ResponseResult result = new ResponseResult();
        Object id = null;
        try {
            Claims claimsBody = getClaimsBody(token);
            id = claimsBody.get("id");

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("token过期无效");
            result.setData(0);
            result.setErrorMessage("token过期无效");
            return result;
        }
        System.out.println("解析token成功 ==> 用户的id值 == "+ id);

        List<MessageVo> messageVo=messageMapper.findMessage((int)id);
        result.setCode(200);
        result.setData(messageVo);
        return result;
    }
}




